<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
   
</head>
<body>  
    <!-- 组件之间的通信 子传父 -->
    <div id="app">
        <child-com ref="myChild"></child-com>
        <button @click="getCom">获取子组件对象</button>
        <span>-------子对象数据：{{ childMsg }}</span>
    </div>
    <script>
        // 在子组件的实例上设置一个ref属性，然后在父组件中使用this.$refs.(设置的ref属性名)得到子组件对象
        Vue.component("childCom",{
            template:`
                <div>123</div>
            `,
            data(){
                return {
                    msg:"hello world"
                }
            }
        })
        var app = new Vue({
            el: "#app",
            data:{
                childMsg: ""
            },
            methods: {
                getCom(){
                    console.log(this.$refs.myChild.msg)
                    this.childMsg = this.$refs.myChild.msg
                }
            }
        });
    </script>
</body>
</html>